<template>
  <ElCard header="辅助检查">
    <el-form :model="formModel" ref="formRef" :show-message="false" size="small">
      <CardBox header="血常规">
        <ElFormItem label="血红蛋白" prop="a00_04_109" v-if="!isHealthCheck">
          <ElInput
            v-model="formModel.a00_04_109"
            type="number"
            :max="500"
            :min="1"
          >
            <template #append>g/L</template>
          </ElInput>
        </ElFormItem>
        <ElFormItem label="白细胞" prop="a00_04_110" v-if="!isHealthCheck">
          <ElInput
            v-model="formModel.a00_04_110"
            type="number"
            :max="1000"
            :min="1"
          >
            <template #append>x10<sup>9</sup>/L</template>
          </ElInput>
        </ElFormItem>
        <br />
        <ElFormItem label="血小板" prop="a00_04_111" v-if="!isHealthCheck">
          <ElInput
            v-model="formModel.a00_04_111"
            type="number"
            :max="5000"
            :min="1"
          >
            <template #append>x10<sup>9</sup>/L</template>
          </ElInput>
        </ElFormItem>
        <ElFormItem label="其他" prop="a00_04_112">
          <ElInput v-model="formModel.a00_04_112" />
        </ElFormItem>
      </CardBox>
      <br />
      <CardBox header="尿常规" v-if="!isHealthCheck">
        <ElFormItem label="尿蛋白" prop="a00_04_113">
          <ElInput
            v-model="formModel.a00_04_113"
            maxlength="5"
            show-word-limit
          />
        </ElFormItem>
        <ElFormItem label="尿糖" prop="a00_04_114">
          <ElInput
            v-model="formModel.a00_04_114"
            maxlength="5"
            show-word-limit
          />
        </ElFormItem>
        <ElFormItem label="尿酮体" prop="a00_04_115">
          <ElInput
            v-model="formModel.a00_04_115"
            maxlength="5"
            show-word-limit
          />
        </ElFormItem>
        <ElFormItem label="尿潜血" prop="a00_04_116">
          <ElInput
            v-model="formModel.a00_04_116"
            maxlength="5"
            show-word-limit
          />
        </ElFormItem>
        <ElFormItem label="其他" prop="a00_04_117">
          <ElInput
            v-model="formModel.a00_04_117"
            maxlength="25"
            show-word-limit
          />
        </ElFormItem>
      </CardBox>
      <br />
      <CardBox header="空腹血糖">
        <ElFormItem prop="a00_04_108">
          <ElInput v-model="formModel.a00_04_108" :max="200" :min="0">
            <template #append>mmol/L</template>
          </ElInput>
        </ElFormItem>
        <ElFormItem prop="a00_04_192" label="或">
          <ElInput
            type="number"
            v-model="formModel.a00_04_192"
            :max="200"
            :min="0"
          >
            <template #append>mg/dL</template>
          </ElInput>
        </ElFormItem>
      </CardBox>
      <br />
      <CardBox header="心电图" v-if="!isHealthCheck">
        <ElFormItem prop="a00_04_137" label="">
          <ElRadioGroup
            v-model="formModel.a00_04_137"
            @change="handleStringExcludeClear($event, '2', ['a00_04_138'])"
          >
            <ElRadio
              v-for="(value, key) in formSource.normal_abnormal"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_138"
          label=" "
          :required="formModel.a00_04_137 === '2'"
        >
          <ElInput
            v-model="formModel.a00_04_138"
            :disabled="formModel.a00_04_137 !== '2'"
            maxlength="25"
            show-word-limit
          />
        </ElFormItem>
      </CardBox>
      <br />
      <CardBox header="尿微量白蛋白">
        <ElFormItem prop="a00_04_118">
          <ElInput
            type="number"
            v-model="formModel.a00_04_118"
            :max="300"
            :min="0"
          />
          mg/dL
        </ElFormItem>
      </CardBox>
      <br />
      <CardBox header="大便潜血">
        <ElFormItem prop="a00_04_119">
          <ElRadioGroup v-model="formModel.a00_04_119">
            <ElRadio
              v-for="(value, key) in formSource.neg_or_pos"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
      </CardBox>
      <br />
      <CardBox header="糖化血红蛋白">
        <ElFormItem prop="a00_04_133">
          <ElInput
            type="number"
            v-model="formModel.a00_04_133"
            :max="100"
            :min="0"
          >
            <template #append> %</template>
          </ElInput>
        </ElFormItem>
      </CardBox>
      <br />
      <CardBox header="乙型肝炎表面抗原">
        <ElFormItem prop="a00_04_134">
          <ElRadioGroup v-model="formModel.a00_04_134">
            <ElRadio
              v-for="(value, key) in formSource.neg_or_pos"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
      </CardBox>
      <br />
      <CardBox header="肝功能">
        <ElFormItem prop="a00_04_120" label="血清谷丙转氨酶">
          <ElInput
            type="number"
            v-model="formModel.a00_04_120"
            :max="1300"
            :min="0"
          >
            <template #append>mg/dL</template>
          </ElInput>
        </ElFormItem>
        <ElFormItem prop="a00_04_121" label="血清谷草转氨酶">
          <ElInput
            type="number"
            v-model="formModel.a00_04_121"
            :max="200"
            :min="0"
          >
            <template #append>U/L</template>
          </ElInput>
        </ElFormItem>
        <ElFormItem prop="a00_04_122" label="白蛋白">
          <ElInput
            type="number"
            v-model="formModel.a00_04_122"
            :max="200"
            :min="0"
          >
            <template #append>g/L</template>
          </ElInput>
        </ElFormItem>
        <ElFormItem prop="a00_04_123" label="总胆红素">
          <ElInput
            type="number"
            v-model="formModel.a00_04_123"
            :max="500"
            :min="0"
          >
            <template #append>μmol/L</template>
          </ElInput>
        </ElFormItem>
        <ElFormItem prop="a00_04_124" label="结合胆红素">
          <ElInput
            type="number"
            v-model="formModel.a00_04_124"
            :max="500"
            :min="0"
          >
            <template #append>μmol/L</template>
          </ElInput>
        </ElFormItem>
      </CardBox>
      <br />
      <CardBox header="肾功能">
        <ElFormItem prop="a00_04_125" v-if="!isHealthCheck" label="血清肌酐">
          <ElInput
            type="number"
            v-model="formModel.a00_04_125"
            :max="1300"
            :min="0"
          >
            <template #append>μmol/L</template>
          </ElInput>
        </ElFormItem>
        <ElFormItem prop="a00_04_126" v-if="!isHealthCheck" label="血尿素氮">
          <ElInput
            type="number"
            v-model="formModel.a00_04_126"
            :max="200"
            :min="0"
          >
            <template #append>mmol/L</template>
          </ElInput>
        </ElFormItem>
        <ElFormItem prop="a00_04_127" label="血钾浓度">
          <ElInput
            type="number"
            v-model="formModel.a00_04_127"
            :max="200"
            :min="0"
          >
            <template #append>mmol/L</template>
          </ElInput>
        </ElFormItem>
        <ElFormItem prop="a00_04_128" label="血钠浓度">
          <ElInput
            type="number"
            v-model="formModel.a00_04_128"
            :max="500"
            :min="0"
          >
            <template #append>mmol/L</template>
          </ElInput>
        </ElFormItem>
      </CardBox>
      <CardBox header="血脂" v-if="!isHealthCheck">
        <ElFormItem prop="a00_04_129" v-if="!isHealthCheck" label="总胆固醇">
          <ElInput
            type="number"
            v-model="formModel.a00_04_129"
            :max="200"
            :min="0"
          >
            <template #append>mmol/L</template>
          </ElInput>
        </ElFormItem>
        <ElFormItem prop="a00_04_130" label="甘油三酯" v-if="!isHealthCheck">
          <ElInput
            type="number"
            v-model="formModel.a00_04_130"
            :max="30"
            :min="0"
          >
            <template #append>mmol/L</template>
          </ElInput>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_131"
          label="血清低密度脂蛋白胆固醇"
          v-if="!isHealthCheck"
        >
          <ElInput
            type="number"
            v-model="formModel.a00_04_131"
            :max="200"
            :min="0"
          >
            <template #append>mmol/L</template>
          </ElInput>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_132"
          label="血清高密度脂蛋白胆固醇"
          v-if="!isHealthCheck"
        >
          <ElInput
            type="number"
            v-model="formModel.a00_04_132"
            :max="500"
            :min="0"
          >
            <template #append>mmol/L</template>
          </ElInput>
        </ElFormItem>
      </CardBox>

      <br />
      <CardBox header="胸部X线片">
        <ElFormItem prop="a00_04_139" label="">
          <ElRadioGroup
            v-model="formModel.a00_04_139"
            @change="handleStringExcludeClear($event, '2', ['a00_04_140'])"
          >
            <ElRadio
              v-for="(value, key) in formSource.normal_abnormal"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_140"
          label=" "
          :required="formModel.a00_04_139 === '2'"
        >
          <ElInput
            v-model="formModel.a00_04_140"
            :disabled="formModel.a00_04_139 !== '2'"
            maxlength="50"
            show-word-limit
          />
        </ElFormItem>
      </CardBox>
      <br />
      <CardBox header="B超" v-if="!isHealthCheck">
        <ElFormItem prop="a00_04_141f" label="腹部B超">
          <ElRadioGroup
            v-model="formModel.a00_04_141f"
            @change="handleStringExcludeClear($event, '2', ['a00_04_142f'])"
          >
            <ElRadio
              v-for="(value, key) in formSource.normal_abnormal"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_142f"
          label=" "
          :required="formModel.a00_04_141f === '2'"
        >
          <ElInput
            v-model="formModel.a00_04_142f"
            :disabled="formModel.a00_04_141f !== '2'"
            maxlength="100"
            show-word-limit
          />
        </ElFormItem>
        <br />
        <ElFormItem prop="a00_04_141" label="其他">
          <ElRadioGroup
            v-model="formModel.a00_04_141"
            @change="handleStringExcludeClear($event, '2', ['a00_04_142'])"
          >
            <ElRadio
              v-for="(value, key) in formSource.normal_abnormal"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_142"
          label=" "
          :required="formModel.a00_04_141 === '2'"
        >
          <ElInput
            v-model="formModel.a00_04_142"
            :disabled="formModel.a00_04_141 !== '2'"
            maxlength="50"
            show-word-limit
          />
        </ElFormItem>
      </CardBox>
      <br />
      <CardBox header="宫颈涂片">
        <ElFormItem prop="a00_04_143" label="">
          <ElRadioGroup
            v-model="formModel.a00_04_143"
            @change="handleStringExcludeClear($event, '2', ['a00_04_144'])"
          >
            <ElRadio
              v-for="(value, key) in formSource.normal_abnormal"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_144"
          label=" "
          :required="formModel.a00_04_143 === '2'"
        >
          <ElInput
            v-model="formModel.a00_04_144"
            :disabled="formModel.a00_04_143 !== '2'"
            maxlength="25"
            show-word-limit
          />
        </ElFormItem>
        <br />
        <ElFormItem prop="a00_04_145" label="其他 ">
          <ElInput
            type="textarea"
            v-model="formModel.a00_04_145"
            maxlength="25"
            show-word-limit
          />
        </ElFormItem>
      </CardBox>
    </el-form>
  </ElCard>
</template>

<script lang="ts" setup>
import { IAuxiliaryCheck } from "@/model";
import { reactive, ref, toRaw } from "vue";
import { tjwx } from "@/dict";
import formUtils from "./formUtils";
import { ElForm } from "element-plus";
import { cloneDeep } from "lodash-es";
import { is } from "@babel/types";
const isHealthCheck = ref<boolean>(import.meta.env.MODE === "health_check");
console.log(import.meta.env.MODE);
console.log(isHealthCheck.value);
const props = defineProps<{
  auxiliaryCheck: IAuxiliaryCheck;
}>();
const formSource = reactive(tjwx);
const formModel = ref(cloneDeep(props.auxiliaryCheck));

const { handleStringExcludeClear } = formUtils(formModel);
const formRef = ref<InstanceType<typeof ElForm>>();
const validateForm = () => {
  return formRef.value?.validate();
};

const getData = () => {
  return toRaw(formModel.value);
};
defineExpose({ validateForm, getData });
</script>
<style scoped lang="scss"></style>
